// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"

tp_ExMalloc* lpExMalloc=NULL;
tp_ExFree* lpExFree=NULL;
HMODULE _3DC;

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		_3DC=GetModuleHandle("3D-CoatGL.exe");
		if(!_3DC)_3DC=GetModuleHandle("3D-CoatDX.exe");
		if(_3DC){
			lpExMalloc=(tp_ExMalloc*)GetProcAddress(_3DC,"?cExMalloc@@YAPAXH@Z");
			lpExFree=(tp_ExFree*)GetProcAddress(_3DC,"?cExFree@@YAXPAX@Z");
		}
		if(lpExMalloc==NULL || lpExFree==NULL){
			MessageBox(0,"Unable to link to 3D-Coat. Please download latest version of 3D-Coat to be able to use plugins.","Plugin error",0);
			return false;
		}
		break;
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}
__declspec(dllexport) float GetSDKVersion(){
	return _3DC_SDK_VER;
}